<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="demo" index="1" class="nav"></div>
    <script>
      var div = document.querySelector('div');
      //1.获取元素属性值
      //1.1    getAttribute ('属性')
      console.log(div.getAttribute('id'), div.getAttribute('index'));
      //2. 设置元素的属性值
      div.id = 'demo123'; //修改id 名
      div.setAttribute('index', 50); //修改已有自定义名
      div.setAttribute('dota', 100); //  如果没有自定义名则为增加
      //3.删除
      div.removeAttribute('id'); //删除id

      
    </script>
  </body>
</html>
